home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / C / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  32.2 KB  |  1,146 lines

  1. /*
  2. **
  3. **    C.generator - Copyright © 1996-1997 Simone Tellini
  4. **                  All Rights Reserved
  5. **
  6. **    This is the standard C generator. You can easily modify this
  7. **    source to adapt it to your own needs.
  8. **
  9. **    You can spread modified copies of this code, provided that you
  10. **    respect these rules:
  11. **    - you MUST leave my name in it; if someone has modified the
  12. **      code before you, you MUST leave his name too
  13. **    - you MUST distribute the new generator in a small archive
  14. **      along with a little doc
  15. **    - the new generator should be FREEWARE, it can NOT be SHAREWARE
  16. **    - you should send me an e-mail telling me what kind of changes
  17. **      you've performed and the name of the archive
  18. **
  19. **
  20. */
  21.  
  22. /// Includes
  23. #define INTUI_V36_NAMES_ONLY
  24.  
  25. #include <exec/types.h>                 // exec
  26. #include <exec/lists.h>
  27. #include <exec/memory.h>
  28. #include <exec/nodes.h>
  29. #include <dos/dos.h>                    // dos
  30. #include <dos/dostags.h>
  31. #include <intuition/intuition.h>        // intuition
  32. #include <intuition/gadgetclass.h>
  33. #include <graphics/text.h>              // graphics
  34. #include <libraries/gadtools.h>         // libraries
  35. #include <libraries/reqtools.h>
  36. #include <clib/exec_protos.h>           // protos
  37. #include <clib/dos_protos.h>
  38. #include <clib/intuition_protos.h>
  39. #include <clib/reqtools_protos.h>
  40. #include <pragmas/exec_pragmas.h>       // pragmas
  41. #include <pragmas/dos_pragmas.h>
  42. #include <pragmas/intuition_pragmas.h>
  43. #include <pragmas/graphics_pragmas.h>
  44. #include <pragmas/gadtools_pragmas.h>
  45. #include <pragmas/reqtools_pragmas.h>
  46.  
  47. #include <string.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <ctype.h>
  51.  
  52. #include "DEV_IE:Generators/defs.h"
  53. #include "DEV_IE:Include/IEditor.h"
  54. #include "DEV_IE:Generators/C/Protos.h"
  55. ///
  56. /// Data
  57. struct CPrefs   Prefs = {
  58.         INTUIMSG | CLICKED | IDCMP_HANDLER | KEY_HANDLER | TO_LOWER,
  59.         0,
  60.         "UWORD __chip",
  61.         "",
  62.         "%s __saveds __asm",
  63.         "register __a%ld stuff"
  64. };
  65.  
  66. ULONG idcmps[] = {
  67.         1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200,
  68.         0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
  69.         0x10000, 0x20000, 0x40000, 0x80000, 0x100000,
  70.         0x200000, 0x400000, 0x800000, 0x1000000,
  71.         0x2000000, 0x4000000
  72.       };
  73.  
  74. ULONG wflgs[] = {
  75.         1, 2, 4, 8, 0x10, 0x20, 0, 0x40, 0x80, 0x100, 0x200,
  76.         0x400, 0x800, 0x1000, 0x10000, 0x20000, 0x40000,
  77.         0x200000
  78.       };
  79.  
  80. UBYTE Header[] =
  81.     "/*\n"
  82.     "    C source code created by Interface Editor\n"
  83.     "    Copyright © 1994-1996 by Simone Tellini\n\n"
  84.     "    Generator:  %s\n"
  85.     "    Copy registered to :  %s\n"
  86.     "    Serial Number      : #%ld\n"
  87.     "*/\n\n";
  88.  
  89. UBYTE   Null[] = "NULL";
  90.  
  91. static UBYTE   ARexxHandleArray[] = "\n"
  92.               "void HandleRexxMsg( void )\n"
  93.               "{\n"
  94.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  95.               "\tWORD\t\tn;\n"
  96.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  97.               "\tstruct RexxMsg\t*RxMsg;\n"
  98.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  99.               "\tUBYTE\t\t*arguments;\n"
  100.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  101.               "\n"
  102.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  103.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  104.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  105.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  106.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  107.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  108.               "\t\t\tRX_Unconfirmed -= 1;\n"
  109.               "\t\t}\n"
  110.               "\t\telse {\n\n"
  111.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  112.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  113.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  114.               "\n"
  115.               "\t\t\tn = 0;\n"
  116.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  117.               "\t\t\t\tcommand[n] = buffer[n];\n"
  118.               "\t\t\t\tn++;\n"
  119.               "\t\t\t};\n"
  120.               "\t\t\tcommand[n] = '\\0';\n\n"
  121.               "\t\t\tn = 0;\n"
  122.               "\t\t\twhile( CmdTable[n].command ) {\n"
  123.               "\t\t\t\tif( stricmp( CmdTable[n].command, command ) == 0 ) {\n"
  124.               "\t\t\t\t\tfound = TRUE;\n"
  125.               "\t\t\t\t\tbreak;\n"
  126.               "\t\t\t\t} else\n"
  127.               "\t\t\t\t\tn++;\n"
  128.               "\t\t\t};\n\n"
  129.               "\t\t\tif( found ) {\n"
  130.               "\t\t\t\tif( CmdTable[n].template ) {\n"
  131.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  132.               "\t\t\t\t\t\targuments = buffer + strlen( CmdTable[n].command );\n\n"
  133.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  134.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  135.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  136.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  137.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  138.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  139.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  140.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  141.               "\n"
  142.               "\t\t\t\t\t\tif( rdargs = ReadArgs( CmdTable[n].template, ArgArray, args )) {\n\n"
  143.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n"
  144.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  145.               "\t\t\t\t\t\t} else\n"
  146.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  147.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  148.               "\t\t\t\t\t} else\n"
  149.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  150.               "\t\t\t\t} else\n"
  151.               "\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n\n"
  152.               "\t\t\t} else {\n\n"
  153.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  154.               "\t\t\t\t\tfail = TRUE;\n\n"
  155.               "\t\t\t};\n\n"
  156.               "\t\t\tif( fail )\n"
  157.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  158.               "\t\t\tif( found )\n"
  159.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  160.               "\t\t}\n"
  161.               "\t}\n"
  162.               "}\n";
  163.  
  164. static UBYTE   ARexxHandleList[] = "\n"
  165.               "void HandleRexxMsg( void )\n"
  166.               "{\n"
  167.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  168.               "\tWORD\t\tn;\n"
  169.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  170.               "\tstruct RexxMsg\t*RxMsg;\n"
  171.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  172.               "\tUBYTE\t\t*arguments;\n"
  173.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  174.               "\n"
  175.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  176.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  177.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  178.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  179.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  180.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  181.               "\t\t\tRX_Unconfirmed -= 1;\n"
  182.               "\t\t}\n"
  183.               "\t\telse {\n\n"
  184.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  185.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  186.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  187.               "\n"
  188.               "\t\t\tn = 0;\n"
  189.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  190.               "\t\t\t\tcommand[n] = buffer[n];\n"
  191.               "\t\t\t\tn++;\n"
  192.               "\t\t\t};\n"
  193.               "\t\t\tcommand[n] = '\\0';\n\n"
  194.               "\t\t\tn = 0;\n"
  195.               "\t\t\tstruct CmdNode *Cmd;\n"
  196.               "\t\t\tfor( Cmd = RexxCommands.mlh_Head; Cmd->Node.ln_Succ; Cmd = Cmd->Node.ln_Succ ) {\n"
  197.               "\t\t\t\tif( stricmp( Cmd->Node.ln_Name, command ) == 0 ) {\n"
  198.               "\t\t\t\t\tfound = TRUE;\n"
  199.               "\t\t\t\t\tbreak;\n"
  200.               "\t\t\t\t}"
  201.               "\t\t\t};\n\n"
  202.               "\t\t\tif( found ) {\n"
  203.               "\t\t\t\tif( Cmd->Template ) {\n"
  204.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  205.               "\t\t\t\t\t\targuments = buffer + strlen( Cmd->Node.ln_Name );\n\n"
  206.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  207.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  208.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  209.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  210.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  211.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  212.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  213.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  214.               "\n"
  215.               "\t\t\t\t\t\tif( rdargs = ReadArgs( Cmd->Template, ArgArray, args )) {\n\n"
  216.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n"
  217.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  218.               "\t\t\t\t\t\t} else\n"
  219.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  220.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  221.               "\t\t\t\t\t} else\n"
  222.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  223.               "\t\t\t\t} else\n"
  224.               "\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n\n"
  225.               "\t\t\t} else {\n\n"
  226.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  227.               "\t\t\t\t\tfail = TRUE;\n\n"
  228.               "\t\t\t};\n\n"
  229.               "\t\t\tif( fail )\n"
  230.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  231.               "\t\t\tif( found )\n"
  232.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  233.               "\t\t}\n"
  234.               "\t}\n"
  235.               "}\n";
  236.  
  237.  
  238. static UBYTE   ARexxCode[] = "\nBOOL SetupRexxPort( void )\n"
  239.               "{\n"
  240.               "\tUWORD\t\tcnt = 0;\n"
  241.               "\n"
  242.               "\tForbid();\n"
  243.               "\n"
  244.               "\tdo {\n"
  245.               "\t\tcnt += 1;\n"
  246.               "\t\tsprintf( RexxPortName, RexxPort_fmt, cnt );\n"
  247.               "\t} while( FindPort( RexxPortName ));\n"
  248.               "\n"
  249.               "\tRexxPort = CreateMsgPort();\n"
  250.               "\tif (!RexxPort) {\n"
  251.               "\t\tPermit();\n"
  252.               "\t\treturn( FALSE );\n"
  253.               "\t};\n"
  254.               "\n"
  255.               "\tRexxPort->mp_Node.ln_Name = RexxPortName;\n"
  256.               "\tRexxPort->mp_Node.ln_Pri  = 0;\n"
  257.               "\n"
  258.               "\tAddPort( RexxPort );\n\n"
  259.               "\tPermit();\n\n"
  260.               "\treturn( TRUE );\n"
  261.               "}\n"
  262.               "\n"
  263.               "void DeleteRexxPort( void )\n"
  264.               "{\n"
  265.               "\tAPTR\tm;\n\n"
  266.               "\tif (!RexxPort)\n"
  267.               "\t\treturn;\n"
  268.               "\n"
  269.               "\twhile( RX_Unconfirmed ) {\n"
  270.               "\t\tWaitPort( RexxPort );\n"
  271.               "\t\tHandleRexxMsg();\n"
  272.               "\t};\n"
  273.               "\n"
  274.               "\tForbid();\n"
  275.               "\tRemPort( RexxPort );\n\n"
  276.               "\twhile( m = GetMsg( RexxPort ))\n"
  277.               "\t\tReplyMsg( m );\n\n"
  278.               "\tDeleteMsgPort( RexxPort );\n"
  279.               "\tRexxPort = NULL;\n"
  280.               "\tPermit();\n"
  281.               "}\n"
  282.               "\n"
  283.               "BOOL SendRexxMsg( char *Host, char *Ext, char *Command, APTR Msg, LONG Flags )\n"
  284.               "{\n"
  285.               "\tAPTR\t\tstring;\n"
  286.               "\tstruct MsgPort\t*Port;\n"
  287.               "\tstruct RexxMsg\t*RxMsg;\n\n"
  288.               "\tif(!( RexxPort ))\n"
  289.               "\t\treturn( FALSE );\n"
  290.               "\n"
  291.               "\tif(!( RxMsg = CreateRexxMsg( RexxPort, Ext, RexxPortName )))\n"
  292.               "\t\treturn( FALSE );\n"
  293.               "\n"
  294.               "\tif(!( string = CreateArgstring( Command, strlen( Command )))) {\n"
  295.               "\t\tDeleteRexxMsg( RxMsg );\n"
  296.               "\t\treturn( FALSE );\n"
  297.               "\t};\n\n"
  298.               "\tRxMsg->rm_Args[0]  = string;\n"
  299.               "\tRxMsg->rm_Args[15] = Msg;\n"
  300.               "\tRxMsg->rm_Action   = Flags | RXCOMM;\n"
  301.               "\n"
  302.               "\tForbid();\n"
  303.               "\tif( Port = FindPort( Host ))\n"
  304.               "\t\tPutMsg( Port, ( struct Message * )RxMsg );\n"
  305.               "\tPermit();\n\n"
  306.               "\tif( Port ) {\n"
  307.               "\t\tRX_Unconfirmed += 1;\n"
  308.               "\t\treturn( TRUE );\n"
  309.               "\t} else {\n"
  310.               "\t\tDeleteArgstring( string );\n"
  311.               "\t\tDeleteRexxMsg( RxMsg );\n"
  312.               "\t\treturn( FALSE );\n"
  313.               "\t};\n"
  314.               "}\n";
  315.  
  316. ///
  317.  
  318.  
  319. //  ***  Main Routines  ***
  320. /// GrabOldPrefs
  321. void GrabOldPrefs( struct IE_Data *IE )
  322. {
  323.     if(!( PrefsOK )) {
  324.  
  325.     Prefs.Flags = IE->C_Prefs;
  326.  
  327.     strcpy( Prefs.ChipString, IE->ChipString );
  328.  
  329.     PrefsOK = TRUE;
  330.     }
  331. }
  332. ///
  333.  
  334. /// OpenFiles
  335. struct GenFiles *OpenFiles( __A0 struct IE_Data *IE, __A1 UBYTE *BaseName )
  336. {
  337.     UBYTE               buffer[1024], buffer2[1024];
  338.     UBYTE              *ptr, *ptr2, *ptr3;
  339.     struct GenFiles    *Files;
  340.  
  341.     GrabOldPrefs( IE );
  342.  
  343.     if(!( Files = AllocMem( sizeof( struct GenFiles ), MEMF_CLEAR )))
  344.     return( NULL );
  345.  
  346.     ptr2 = FilePart( BaseName );
  347.  
  348.     ptr  = BaseName;
  349.     ptr3 = buffer;
  350.     while( ptr != ptr2 )
  351.     *ptr3++ = *ptr++;
  352.  
  353.     *ptr3 = '\0';
  354.  
  355.     ptr = buffer2;
  356.     while(( *ptr2 != '.' ) && ( *ptr2 ))
  357.     *ptr++ = *ptr2++;
  358.     *ptr = '\0';
  359.  
  360.     AddPart( buffer, buffer2, 1024 );
  361.  
  362.     strcpy( buffer2, buffer );
  363.     strcat( buffer2, ".c" );
  364.  
  365.     if(!( Files->Std = Open( buffer2, MODE_NEWFILE )))
  366.     return( NULL );
  367.  
  368.     strcpy( buffer2, buffer );
  369.     strcat( buffer2, ".h" );
  370.     strcpy( Files->XDefName, buffer2 );
  371.  
  372.     if(!( Files->XDef = Open( buffer2, MODE_NEWFILE )))
  373.     goto error;
  374.  
  375.  
  376.     if( Prefs.Flags & GEN_TEMPLATE ) {
  377.  
  378.     strcpy( buffer2, buffer );
  379.     strcat( buffer2, "_temp.c" );
  380.  
  381.     if(!( Files->Temp = Open( buffer2, MODE_NEWFILE )))
  382.         goto error;
  383.  
  384.     }
  385.  
  386.     if( IE->SrcFlags & MAINPROC ) {
  387.  
  388.     strcpy( buffer2, buffer );
  389.     strcat( buffer2, "Main.c" );
  390.  
  391.     if( AskFile( buffer2, IE ))
  392.         if(!( Files->Main = Open( buffer2, MODE_NEWFILE )))
  393.         goto error;
  394.     }
  395.  
  396.     if( IE->SrcFlags & LOCALIZE ) {
  397.     Files->User1 = IE;
  398.     Prefs.Flags |= SMART_STR;
  399.     }
  400.  
  401.     return( Files );
  402.  
  403.  
  404. error:
  405.  
  406.     CloseFiles( Files );
  407.  
  408.     return( NULL );
  409. }
  410. ///
  411. /// CloseFiles
  412. void CloseFiles( __A0 struct GenFiles *Files )
  413. {
  414.     if( Files ) {
  415.     if( Files->Std   )  Close( Files->Std   );
  416.     if( Files->Temp  )  Close( Files->Temp  );
  417.     if( Files->XDef  )  Close( Files->XDef  );
  418.     if( Files->Main  )  Close( Files->Main  );
  419.  
  420.     if( Files->User1 ) {
  421.         UBYTE  *from, *to, *ptr;
  422.         UBYTE   path[256], locale[256];
  423.  
  424.         /* get the path where the files must be created */
  425.  
  426.         from = Files->XDefName;
  427.         to   = FilePart( Files->XDefName );
  428.         ptr  = path;
  429.  
  430.         while( from < to )
  431.         *ptr++ = *from++;
  432.  
  433.         *ptr = '\0';
  434.  
  435.         /* build the name of the locale file */
  436.  
  437.         ptr = locale;
  438.  
  439.         while( *to != '.' )
  440.         *ptr++ = *to++;
  441.  
  442.         *ptr = '\0';
  443.  
  444.         strcat( locale, "_Locale.h" );
  445.  
  446.  
  447.         if( Prefs.MoreFlags & USE_CATCOMP ) {
  448.         UBYTE   command[ 1024 ];
  449.  
  450.         /* built the command line */
  451.  
  452.         strcpy( command, "CatComp \"" );
  453.         strcat( command, path );
  454.         strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
  455.         strcat( command, ".cd\" CFILE \"" );
  456.         strcat( command, path );
  457.         strcat( command, locale );
  458.         strcat( command, "\"" );
  459.  
  460.         /* and execute it */
  461.  
  462.         SystemTagList( command, NULL );
  463.  
  464.         } else {
  465.         AddPart( path, locale, 256 );
  466.         WriteLocaleH( Files, (struct IE_Data *)Files->User1, path );
  467.         }
  468.     }
  469.  
  470.     FreeMem( Files, sizeof( struct GenFiles ));
  471.     }
  472. }
  473. ///
  474.  
  475. /// WriteHeaders
  476. BOOL WriteHeaders( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  477. {
  478.     APTR                UserHeaders = NULL;
  479.     struct WindowInfo  *wnd;
  480.     struct GadgetInfo  *gad;
  481.     ULONG               cnt;
  482.  
  483.  
  484.     if( Prefs.HeadersFile[0] ) {
  485.     ULONG   size;
  486.     BPTR    file;
  487.  
  488.     if( file = Open( Prefs.HeadersFile, MODE_OLDFILE )) {
  489.  
  490.         Seek( file, 0, OFFSET_END );
  491.         size = Seek( file, 0, OFFSET_BEGINNING );
  492.  
  493.         if( UserHeaders = AllocVec( size, MEMF_ANY )) {
  494.  
  495.         Read( file, UserHeaders, size );
  496.  
  497.         ( *IE->IEXFun->SplitLines )( UserHeaders ); // VERY important!
  498.         }
  499.  
  500.         Close( file );
  501.     }
  502.     }
  503.  
  504.  
  505.     FPrintf( Files->Std,  Header, LibId, IE->User->Name, IE->User->Number );
  506.     FPrintf( Files->XDef, Header, LibId, IE->User->Name, IE->User->Number );
  507.  
  508.     if( Files->Temp ) {
  509.     FPrintf( Files->Temp, Header, LibId, IE->User->Name, IE->User->Number );
  510.  
  511.     FPuts( Files->Temp,
  512.         "/*\n"
  513.         "   In this file you'll find empty  template  routines\n"
  514.         "   referenced in the GUI source.  You  can fill these\n"
  515.         "   routines with your code or use them as a reference\n"
  516.         "   to create your main program.\n"
  517.         "*/\n\n"
  518.         "#include <stdio.h>\n"
  519.         "#include <exec/types.h>\n\n" );
  520.     }
  521.  
  522.     if( Files->Main ) {
  523.     FPrintf( Files->Main, Header, LibId, IE->User->Name, IE->User->Number );
  524.     WriteMain( Files, IE );
  525.     }
  526.  
  527.     if( UserHeaders == NULL ) {
  528.  
  529.     FPuts( Files->Std, "#include <exec/types.h>\n"
  530.                "#include <exec/nodes.h>\n"
  531.                "#include <intuition/intuition.h>\n"
  532.                "#include <intuition/gadgetclass.h>\n"
  533.                "#include <graphics/clip.h>\n"
  534.                "#include <graphics/gfxmacros.h>\n"
  535.                "#include <libraries/gadtools.h>\n"
  536.                "#include <clib/exec_protos.h>\n"
  537.                "#include <clib/intuition_protos.h>\n"
  538.                "#include <clib/gadtools_protos.h>\n"
  539.                "#include <clib/graphics_protos.h>\n"
  540.                "#ifdef PRAGMAS\n"
  541.                "#include <pragmas/exec_pragmas.h>\n"
  542.                "#include <pragmas/intuition_pragmas.h>\n"
  543.                "#include <pragmas/graphics_pragmas.h>\n"
  544.                "#include <pragmas/gadtools_pragmas.h>\n"
  545.                "#endif\n"
  546.                "#include <ctype.h>\n"
  547.                "#include <string.h>\n\n" );
  548.  
  549.     FPuts( Files->XDef, "#ifndef EXEC_TYPES_H\n"
  550.                 "#include <exec/types.h>\n"
  551.                 "#endif\n"
  552.                 "#ifndef EXEC_NODES_H\n"
  553.                 "#include <exec/nodes.h>\n"
  554.                 "#endif\n"
  555.                 "#ifndef INTUITION_INTUITION_H\n"
  556.                 "#include <intuition/intuition.h>\n"
  557.                 "#endif\n"
  558.                 "#ifndef INTUITION_GADGETCLASS_H\n"
  559.                 "#include <intuition/gadgetclass.h>\n"
  560.                 "#endif\n"
  561.                 "#ifndef LIBRARIES_GADTOOLS_H\n"
  562.                 "#include <libraries/gadtools.h>\n"
  563.                 "#endif\n"
  564.                 "#ifndef CLIB_EXEC_PROTOS_H\n"
  565.                 "#include <clib/exec_protos.h>\n"
  566.                 "#endif\n"
  567.                 "#ifndef CLIB_INTUITION_PROTOS_H\n"
  568.                 "#include <clib/intuition_protos.h>\n"
  569.                 "#endif\n"
  570.                 "#ifndef CLIB_GADTOOLS_PROTOS_H\n"
  571.                 "#include <clib/gadtools_protos.h>\n"
  572.                 "#endif\n"
  573.                 "#ifndef CLIB_GRAPHICS_PROTOS_H\n"
  574.                 "#include <clib/graphics_protos.h>\n"
  575.                 "#endif\n"
  576.                 "#ifndef CTYPE_H\n"
  577.                 "#include <ctype.h>\n"
  578.                 "#endif\n"
  579.                 "#ifndef STRING_H\n"
  580.                 "#include <string.h>\n"
  581.                 "#endif\n\n" );
  582.     } else {
  583.     STRPTR  inc;
  584.  
  585.     if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "STANDARD" )) {
  586.  
  587.         FPuts( Files->Std,  inc );
  588.         FPuts( Files->XDef, inc );
  589.     }
  590.     }
  591.  
  592.  
  593.     if( CheckMultiSelect( IE ))
  594.     FPuts( Files->XDef, "#include <utility/hooks.h>\n" );
  595.  
  596.  
  597.     if( IE->SrcFlags & OPENDISKFONT ) {
  598.     if( UserHeaders ) {
  599.         STRPTR  inc;
  600.  
  601.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "DISKFONT" ))
  602.         FPuts( Files->Std,  inc );
  603.  
  604.     } else
  605.         FPuts( Files->Std, "#include <clib/diskfont_protos.h>\n\n" );
  606.     }
  607.  
  608.     if( IE->NumRexxs ) {
  609.     if( UserHeaders ) {
  610.         STRPTR  inc;
  611.  
  612.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "AREXX" ))
  613.         FPuts( Files->Std,  inc );
  614.  
  615.     } else
  616.         FPuts( Files->Std, "#include <rexx/rxslib.h>\n"
  617.                    "#include <rexx/rexxio.h>\n"
  618.                    "#include <rexx/errors.h>\n"
  619.                    "#include <rexx/storage.h>\n"
  620.                    "#include <dos/dos.h>\n"
  621.                    "#include <dos/rdargs.h>\n"
  622.                    "#include <clib/dos_protos.h>\n"
  623.                    "#include <clib/rexxsyslib_protos.h>\n"
  624.                    "#include <clib/alib_stdio_protos.h>\n"
  625.                    "#ifdef PRAGMAS\n"
  626.                    "#include <pragmas/dos_pragmas.h>\n"
  627.                    "#include <pragmas/rexxsyslib_pragmas.h>\n"
  628.                    "#endif\n\n" );
  629.     }
  630.  
  631.     if( IE->SrcFlags & LOCALIZE ) {
  632.     if( UserHeaders ) {
  633.         STRPTR  inc;
  634.  
  635.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "LOCALE" ))
  636.         FPuts( Files->Std,  inc );
  637.  
  638.     } else
  639.        FPuts( Files->Std, "#include <libraries/locale.h>\n"
  640.                    "#include <clib/locale_protos.h>\n"
  641.                    "#ifdef PRAGMAS\n"
  642.                    "#include <pragmas/locale_pragmas.h>\n"
  643.                    "#endif\n\n" );
  644.     }
  645.  
  646.     FPrintf( Files->Std, "#include \"%s\"\n\n", FilePart( Files->XDefName ));
  647.  
  648.     if( IE->SrcFlags & LOCALIZE ) {
  649.  
  650.     UBYTE   *to, buffer[60];
  651.  
  652.     strcpy( buffer, FilePart( Files->XDefName ));
  653.  
  654.     to = strrchr( buffer, '.' );
  655.     *to = '\0';
  656.  
  657.     strcat( buffer, "_Locale.h" );
  658.  
  659.     FPrintf( Files->Std, "#define CATCOMP_ARRAY\n"
  660.                  "#include \"%s\"\n\n",
  661.          buffer );
  662.     }
  663.  
  664.  
  665.     FPuts( Files->XDef, "#define GetString( g )\t((( struct StringInfo * )g->SpecialInfo )->Buffer  )\n"
  666.             "#define GetNumber( g )\t((( struct StringInfo * )g->SpecialInfo )->LongInt )\n\n"
  667.             "#define WT_LEFT\t\t\t\t0\n"
  668.             "#define WT_TOP\t\t\t\t1\n"
  669.             "#define WT_WIDTH\t\t\t2\n"
  670.             "#define WT_HEIGHT\t\t\t3\n\n" );
  671.  
  672.     for( cnt = 0; cnt < 3; cnt++ ) {
  673.     TEXT    buf[32];
  674.  
  675.     sprintf( buf, Prefs.RegisterDef, cnt );
  676.  
  677.     FPrintf( Files->XDef, "#define A%ld(stuff) %s\n", cnt, buf );
  678.     }
  679.  
  680.  
  681.     if( IE->SrcFlags & LOCALIZE )
  682.     FPuts( Files->XDef, "extern struct CatCompArrayType CatCompArray[];\n"
  683.                 "extern struct Library *LocaleBase;\n\n" );
  684.  
  685.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  686.     struct GadgetBank  *bank;
  687.  
  688.     cnt = 0;
  689.     for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  690.         if( gad->g_Kind < MIN_IEX_ID ) {
  691.         FPrintf( Files->XDef, "#define GD_%s\t\t\t\t\t%ld\n", gad->g_Label, cnt );
  692.         cnt += 1;
  693.         }
  694.  
  695.  
  696.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ )
  697.         for( cnt = 0, gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  698.         if( gad->g_Kind < MIN_IEX_ID ) {
  699.             FPrintf( Files->XDef, "#define GD_%s\t\t\t\t\t%ld\n", gad->g_Label, cnt );
  700.             cnt += 1;
  701.         }
  702.  
  703.  
  704.     if( cnt )
  705.         FPutC( Files->XDef, 10 );
  706.     }
  707.  
  708.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  709.     struct GadgetBank  *bank;
  710.  
  711.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  712.     if( cnt )
  713.         FPrintf( Files->XDef, "#define %s_CNT %ld\n", wnd->wi_Label, cnt );
  714.  
  715.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  716.         struct GadgetInfo  *gad;
  717.  
  718.         for( cnt = 0, gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  719.         if( gad->g_Kind < BOOLEAN )
  720.             cnt += 1;
  721.  
  722.         if( cnt )
  723.         FPrintf( Files->XDef, "#define %s_CNT %ld\n", bank->Label, cnt );
  724.     }
  725.     }
  726.  
  727.     FPutC( Files->XDef, '\n' );
  728.  
  729.     ( *IE->IEXSrcFun->Headers )( Files );
  730.  
  731.     return( TRUE );
  732. }
  733. ///
  734. /// WriteVars
  735. BOOL WriteVars( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  736. {
  737.     int                 cnt;
  738.     struct WindowInfo  *wnd;
  739.  
  740.     FPuts( Files->Std, "APTR\t\t\tVisualInfo;\n"
  741.                "int\t\t\tYOffset;\n"
  742.                "UWORD\t\t\tXOffset;\n"
  743.                "struct Screen\t\t*Scr = NULL;\n" );
  744.  
  745.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  746.     if( wnd->wi_NumGBanks ) {
  747.  
  748.         FPuts( Files->XDef, "struct WindowBanks {\n"
  749.                 "\tstruct Gadget **Banks;\n"
  750.                 "\tUWORD           Count;\n"
  751.                 "};\n\n" );
  752.         break;
  753.     }
  754.  
  755.  
  756.     FPuts( Files->XDef, "extern struct IntuitionBase\t*IntuitionBase;\n"
  757.             "extern struct Library\t\t*GadToolsBase;\n"
  758.             "extern struct Library\t\t*GfxBase;\n"
  759.             "extern struct Screen\t\t*Scr;\n"
  760.             "extern int\t\t\tYOffset;\n"
  761.             "extern UWORD\t\t\tXOffset;\n"
  762.             "extern APTR\t\t\tVisualInfo;\n" );
  763.  
  764.     if( IE->SrcFlags & FONTSENSITIVE )
  765.     FPuts( Files->Std, "struct TextAttr\t\t*Font, Attr;\n"
  766.                "UWORD\t\t\tFontX, FontY;\n" );
  767.  
  768.     if(!( IE->flags_2 & GENERASCR )) {
  769.     FPuts( Files->Std,  "UBYTE\t\t\t*PubScreenName = NULL;\n" );
  770.     FPuts( Files->XDef, "extern UBYTE\t\t\t*PubScreenName;\n" );
  771.     } else {
  772.     if( IE->ScreenData->ScrAttrs & SC_ERRORCODE ) {
  773.         FPuts( Files->Std,  "ULONG\t\t\tScreenError = NULL;\n" );
  774.         FPuts( Files->XDef, "extern ULONG\t\t\tScreenError;\n" );
  775.     }
  776.     }
  777.  
  778.     if( IE->SrcFlags & LOCALIZE ) {
  779.     FPrintf( Files->Std, "UBYTE\t\t\tLocalized[ %ld ];\n"
  780.                  "struct Catalog\t\t*Catalog = NULL;\n",
  781.          IE->num_win );
  782.     FPuts( Files->XDef, "extern struct Catalog\t\t*Catalog;\n" );
  783.     }
  784.  
  785.     if( IE->NumRexxs ) {
  786.     FPrintf( Files->Std, "UWORD\t\t\tRX_Unconfirmed;\n"
  787.                  "struct MsgPort\t\t*RexxPort;\n"
  788.                  "UBYTE\t\t\tRexxPortName[%ld];\n"
  789.                  "const char\t\t*RexxPort_fmt = \"%s.%%d\";\n"
  790.                  "const char\t\t*REXX_ext = \"%s\";\n",
  791.          strlen( IE->RexxPortName ) + 4,
  792.          IE->RexxPortName, IE->RexxExt );
  793.     }
  794.  
  795.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  796.     FPrintf( Files->Std,  "struct Window\t\t*%sWnd = NULL;\n", wnd->wi_Label );
  797.     FPrintf( Files->XDef, "extern struct Window\t\t*%sWnd;\n", wnd->wi_Label );
  798.     }
  799.  
  800.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  801.     if( wnd->wi_NumMenus ) {
  802.         FPrintf( Files->Std,  "struct Menu\t\t*%sMenus = NULL;\n", wnd->wi_Label );
  803.         FPrintf( Files->XDef, "extern struct Menu\t\t*%sMenus;\n", wnd->wi_Label );
  804.     }
  805.     }
  806.  
  807.  
  808.     //      Gadget Lists
  809.  
  810.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  811.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  812.         FPrintf( Files->Std,  "struct Gadget\t\t*%sGList = NULL;\n", wnd->wi_Label );
  813.         FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGList;\n", wnd->wi_Label );
  814.     }
  815.     }
  816.  
  817.  
  818.     //      Gadget Banks
  819.  
  820.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  821.     if( wnd->wi_NumGBanks ) {
  822.         struct GadgetBank  *bank;
  823.  
  824.         FPrintf( Files->Std,  "static struct Gadget\t*%sGBanks[%ld];\n"
  825.                   "struct WindowBanks\t%sWBanks = { &%sGBanks[ 0 ], 0 };\n",
  826.                   wnd->wi_Label, wnd->wi_NumGBanks,
  827.                   wnd->wi_Label, wnd->wi_Label );
  828.         FPrintf( Files->XDef, "extern struct WindowBanks\t\t%sWBanks;\n", wnd->wi_Label );
  829.  
  830.         for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  831.         struct GadgetInfo  *gad;
  832.         ULONG               count = 0;
  833.  
  834.         for( gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  835.             if( gad->g_Kind < BOOLEAN )
  836.             count += 1;
  837.  
  838.         if( count ) {
  839.             FPrintf( Files->Std,  "struct Gadget\t\t*%sGList = NULL;\n"
  840.                       "struct Gadget\t\t*%sGadgets[%ld];\n",
  841.                       bank->Label, bank->Label, count );
  842.  
  843.             FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGList;\n"
  844.                       "extern struct Gadget\t\t*%sGadgets[%ld];\n",
  845.                      bank->Label, bank->Label, count );
  846.         }
  847.         }
  848.     }
  849.     }
  850.  
  851.  
  852.     //      IntuiMessages
  853.  
  854.     if( Prefs.Flags & INTUIMSG ) {
  855.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  856.         if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))) {
  857.         FPrintf( Files->Std,  "struct IntuiMessage\t%sMsg;\n", wnd->wi_Label );
  858.         FPrintf( Files->XDef, "extern struct IntuiMessage\t%sMsg;\n", wnd->wi_Label );
  859.         }
  860.     }
  861.     }
  862.  
  863.  
  864.  
  865.     //      Gadget Pointers Arrays
  866.  
  867.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  868.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  869.     if( cnt ) {
  870.         FPrintf( Files->Std,  "struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
  871.         FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
  872.     }
  873.     }
  874.  
  875.  
  876.     if( IE->SrcFlags & SHARED_PORT ) {
  877.     Files->User2 = IE->SharedPort[0] ? (APTR)&IE->SharedPort[0] : (APTR)"IDCMPPort";
  878.  
  879.     FPrintf( Files->XDef, "extern struct MsgPort\t\t*%s;\n"
  880.                   "extern struct IntuiMessage\tIDCMPMsg;\n"
  881.                   "extern LONG OpenWndShd( struct Gadget *, struct TagItem *, struct Window **, ULONG );\n"
  882.                   "extern void CloseWndShd( struct Window **, struct Gadget **, struct Menu ** );\n"
  883.                   "extern void HandleIDCMPPort( void );\n",
  884.          Files->User2 );
  885.  
  886.     if(!( IE->SharedPort[0] ))
  887.         FPuts( Files->Std, "\nstruct MsgPort\t\t*IDCMPPort;\n" );
  888.  
  889.     FPuts( Files->Std, "struct IntuiMessage\tIDCMPMsg;\n" );
  890.     }
  891.  
  892.  
  893.     // Expanders
  894.     ( *IE->IEXSrcFun->Globals )( Files );
  895.  
  896.     if( IE->SrcFlags & OPENDISKFONT )
  897.     WriteFontPtrs( Files, IE );
  898.  
  899.     return( TRUE );
  900. }
  901. ///
  902. /// WriteData
  903. BOOL WriteData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  904. {
  905.     struct WindowInfo  *wnd;
  906.     struct TxtAttrNode *fnt;
  907.  
  908.     // Gadget Labels
  909.  
  910.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  911.     WriteGLabels( Files, IE, &wnd->wi_Gadgets, wnd );
  912.  
  913.  
  914.     // Gadget Types
  915.  
  916.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  917.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  918.  
  919.         FPrintf( Files->XDef, "extern UWORD\t\t\t%sGTypes[];\n", wnd->wi_Label );
  920.         FPrintf( Files->Std, "\nUWORD %sGTypes[] = {\n\t", wnd->wi_Label );
  921.  
  922.         WriteGTypes( Files, IE, &wnd->wi_Gadgets );
  923.     }
  924.     }
  925.  
  926.     // Fonts
  927.  
  928.     for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
  929.     FPrintf( Files->XDef, "extern struct TextAttr\t\t%s;\n", fnt->txa_Label );
  930.     FPrintf( Files->Std, "\nstruct TextAttr %s = {\n"
  931.                  "\t(STRPTR)\"%s\", %ld, 0x%lx, 0x%lx };\n",
  932.          fnt->txa_Label, fnt->txa_FontName, fnt->txa_Size,
  933.          fnt->txa_Style, fnt->txa_Flags );
  934.     }
  935.  
  936.     // Gadget Data that should preceed gadget tags
  937.     WriteGadgetExtData( Files, IE );
  938.  
  939.     // NewGadget structures
  940.     WriteNewGadgets( Files, IE );
  941.  
  942.     // Gadget Tags
  943.     WriteGadgetTags( Files, IE );
  944.  
  945.     // Boolean Structures
  946.     WriteBoolStruct( Files, IE );
  947.  
  948.     // Gadget Banks Data
  949.     WriteGadgetBanks( Files, IE );
  950.  
  951.     // Expanders
  952.     ( *IE->IEXSrcFun->Data )( Files );
  953.  
  954.     // Menus
  955.     WriteMenuStruct( Files, IE );
  956.  
  957.     // IntuiTexts
  958.     WriteITexts( Files, IE );
  959.  
  960.     // Images (used by the GUI)
  961.     WriteImgStruct( Files, IE );
  962.  
  963.     // Images (in windows)
  964.     WriteImageStruct( Files, IE );
  965.  
  966.     // Rexx Commands
  967.     WriteRexxCmds( Files, IE );
  968.  
  969.     // Windows' Zoom
  970.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  971.     if( wnd->wi_Tags & W_ZOOM ) {
  972.         FPrintf( Files->XDef, "extern UWORD\t\t\t%sZoom[];\n", wnd->wi_Label );
  973.         FPrintf( Files->Std, "\nUWORD %sZoom[] = { ", wnd->wi_Label );
  974.         VFPrintf( Files->Std, "%d, %d, %d, %d };\n", &wnd->wi_ZLeft );
  975.     }
  976.     }
  977.  
  978.     // Windows Tags
  979.     WriteWindowTags( Files, IE );
  980.  
  981.     // Screen Tags
  982.     if( IE->flags_2 & GENERASCR )
  983.     WriteScreenTags( Files, IE );
  984.  
  985.     return( TRUE );
  986. }
  987. ///
  988. /// WriteChipData
  989. BOOL WriteChipData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  990. {
  991.     struct ImageNode   *img;
  992.     UWORD               words, num, *ptr;
  993.  
  994.     for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
  995.     if( img->in_Size ) {
  996.  
  997.         words = img->in_Size >> 1;
  998.  
  999.         FPrintf( Files->Std, "\n%s %sImgData[%ld] = {\n\t",
  1000.              Prefs.ChipString, img->in_Label, words );
  1001.  
  1002.         FPrintf( Files->XDef, "extern %s %sImgData[%ld];\n",
  1003.              Prefs.ChipString, img->in_Label, words );
  1004.  
  1005.         ptr = img->in_Data;
  1006.  
  1007.         num = 8;
  1008.  
  1009.         do {
  1010.  
  1011.         FPrintf( Files->Std, "0x%04lx", *ptr++ );
  1012.  
  1013.         num   -= 1;
  1014.         words -= 1;
  1015.  
  1016.         if( words ) {
  1017.  
  1018.             FPutC( Files->Std, ',' );
  1019.  
  1020.             if(!( num )) {
  1021.             FPuts( Files->Std, "\n\t" );
  1022.             num = 8;
  1023.             }
  1024.         }
  1025.  
  1026.         } while( words );
  1027.  
  1028.         FPuts( Files->Std, "\n};\n" );
  1029.  
  1030.     }
  1031.     }
  1032.  
  1033.     // Expanders
  1034.     ( *IE->IEXSrcFun->ChipData )( Files );
  1035.  
  1036.     return( TRUE );
  1037. }
  1038. ///
  1039. /// WriteCode
  1040. BOOL WriteCode( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  1041. {
  1042.  
  1043.     // Expanders
  1044.     ( *IE->IEXSrcFun->Support )( Files );
  1045.  
  1046.     if( IE->SrcFlags & SHARED_PORT )
  1047.     WriteOpenWndShd( Files, IE );
  1048.  
  1049.     if( IE->SrcFlags & LOCALIZE )
  1050.     WriteLocale( Files, IE );
  1051.  
  1052.     WriteSetupScr( Files, IE );
  1053.  
  1054.     WriteBackFillHook( Files, IE );
  1055.  
  1056.     WriteListHook( Files, IE );
  1057.  
  1058.     WriteGBanksHandling( Files, IE );
  1059.  
  1060.     WriteOpenFonts( Files, IE );
  1061.  
  1062.     WriteOpenWnd( Files, IE );
  1063.  
  1064.     WriteRender( Files, IE );
  1065.  
  1066.     if( IE->NumRexxs ) {
  1067.     FPuts( Files->Std, ARexxCode );
  1068.  
  1069.     if( IE->SrcFlags & AREXX_CMD_LIST )
  1070.         FPuts( Files->Std, ARexxHandleList );
  1071.     else
  1072.         FPuts( Files->Std, ARexxHandleArray );
  1073.     }
  1074.  
  1075.     if( Prefs.Flags & IDCMP_HANDLER )
  1076.     WriteIDCMPHandler( Files, IE );
  1077.  
  1078.     if( Prefs.Flags & KEY_HANDLER )
  1079.     WriteKeyHandler( Files, IE );
  1080.  
  1081.     FPuts( Files->XDef, "\nextern int SetupScreen( void );\n"
  1082.             "extern void CloseDownScreen( void );\n"
  1083.             "extern struct Gadget *MakeGadgets( struct Gadget **GList, struct Gadget *Gads[],\n"
  1084.             "\tstruct NewGadget NGad[], UWORD GTypes[], ULONG GTags[], UWORD CNT );\n"
  1085.             "extern LONG OpenWnd( struct Gadget *GList, struct TagItem WTags[], struct Window **Wnd );\n"
  1086.             "extern void CloseWnd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn );\n"
  1087.      );
  1088.  
  1089.     if( Prefs.Flags & CLICKED )
  1090.     WriteClickedPtrs( Files, IE );
  1091.  
  1092.     return( TRUE );
  1093. }
  1094. ///
  1095. /// WriteStrings
  1096. BOOL WriteStrings( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  1097. {
  1098.  
  1099.     if(!( IE->SrcFlags & LOCALIZE )) {
  1100.  
  1101.     if( Prefs.Flags & SMART_STR ) {
  1102.         struct LocaleStr   *str;
  1103.  
  1104.         FPutC( Files->Std, 10 );
  1105.  
  1106.         for( str = IE->Locale->ExtraStrings.mlh_Head; str->Node.ln_Succ; str = str->Node.ln_Succ )
  1107.         if( str->Node.ln_Pri & LOC_GUI )
  1108.             break;
  1109.  
  1110.         for( ; str->Node.ln_Succ; str = str->Node.ln_Succ ) {
  1111.  
  1112.         FPrintf( Files->XDef, "extern UBYTE\t\t\t%s[];\n", str->ID );
  1113.  
  1114.         FPrintf( Files->Std, "UBYTE %s[] = \"%s\";\n",
  1115.              str->ID, str->Node.ln_Name );
  1116.         }
  1117.     }
  1118.     }
  1119.  
  1120.     if( Prefs.Flags & SMART_STR ) {
  1121.     struct ArrayNode   *ar;
  1122.     UBYTE             **array;
  1123.  
  1124.     for( ar = IE->Locale->Arrays.mlh_Head; ar->Next; ar = ar->Next ) {
  1125.  
  1126.         FPrintf( Files->XDef, "extern UBYTE\t\t\t*%s[];\n", ar->Label );
  1127.  
  1128.         FPrintf( Files->Std, "\nUBYTE *%s[] = {", ar->Label );
  1129.  
  1130.         array = ar->Array;
  1131.  
  1132.         while( *array ) {
  1133.         FPrintf( Files->Std, "\n\t(UBYTE *)%s,",
  1134.              (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, *array ))->ID );
  1135.         array++;
  1136.         }
  1137.  
  1138.         FPuts( Files->Std, "\n\tNULL\n};\n" );
  1139.     }
  1140.     }
  1141.  
  1142.     return( TRUE );
  1143. }
  1144. ///
  1145.  
  1146.